﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData;
using ZFSData.InterFace;

namespace ZFS.ServerBusiness
{
    public class WCF_DictionaryManager : WCF_BaseManager<WCF_DictionaryManager>, IDictionary
    {
        public tb_Dictionary AddEntity(tb_Dictionary entity)
        {
            var bytes = Server.AddEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool DeleteEntity(tb_Dictionary entity)
        {
            var bytes = Server.DeleteEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public bool ExistEntity(tb_Dictionary entity)
        {
            var bytes = Server.ExistEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_Dictionary> GetDictionarys()
        {
            var bytes = Server.GetDictionarys();
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_Dictionary> GetModels(tb_Dictionary search)
        {
            var bytes = Server.GetModelsByDic(ZipTools.CompressionObject(search));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }

        public List<tb_Dictionary> GetPagingModels(int pageIndex, int pageSize, out int totalCount, tb_Dictionary search, bool Asc = false)
        {
            var bytes = Server.GetPagingModelsByDic(pageIndex, pageSize, ZipTools.CompressionObject(search), Asc);
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
            {
                totalCount = response.TotalCount;
                return response.Results;
            }
            else
                throw new Exception(response.Message);
        }

        public bool UpdateEntity(tb_Dictionary entity)
        {
            byte[] bytes= Server.UpdateEntityByDic(ZipTools.CompressionObject(entity));
            ServiceResponse response = ZipTools.DecompressionObject(bytes) as ServiceResponse;
            if (response.Success)
                return response.Results;
            else
                throw new Exception(response.Message);
        }
    }
}
